{% extends 'base.html' %}
{% block content %}
    <!-- 在模板中可以直接使用 current_user 变量 -->
    {% if current_user.is_authenticated %}
    <form method="post">
        Name <input type="text" name="title" autocomplete="off" required>
        Year <input type="text" name="year" autocomplete="off" required>
        <input class="btn" type="submit" name="submit" value="Add">
    </form>
    {% endif %}
    <p2> {{movies|length}} Titles </p2>
    <ul class="movie-list">
        {% for movie in movies %}
        <li> {{movie.title}} - {{movie.year}} 
            <span class="float-right">
                <a class="imdb" href="https://www.imdb.com/find?q={{ movie.title }}" target="_blank" title="Find this movie on IMDB">IMDB</a>
                {% if current_user.is_authenticated %}
                <a class="btn" href="{{ url_for('edit', movie_id=movie.id) }}">Edit</a>
                <form class="inline-form" method="post" action="{{ url_for('delete', movie_id=movie.id) }}">
                    <input class="btn" type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure?')">
                </form>
                {% endif %}
            </span>
        </li>
        {% endfor %}
    </ul>
    <img alt="Walking Totoro" class="totoro" src="{{url_for("static", filename="images/totoro.gif")}}">
{% endblock %}